﻿<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>HTML5响应式用户登录界面模板</title>
  <meta name="description" content="particles.js is a lightweight JavaScript library for creating particles.">
  <meta name="author" content="Vincent Garreau" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <link rel="stylesheet" media="screen" href="css/style.css">
  <link rel="stylesheet" type="text/css" href="css/reset.css"/>
  <script src="jquery-3.6.1.min.js"></script>
</head>
<style>
	#wo{
		cursor: pointer;
	}
</style>
<body>

<div id="particles-js">
		<div class="login">
			<div class="login-top">
				添加
			</div>
			<div class="login-center clearfix">
				<div class="login-center-img"><img src="img/name.png"/></div>
				<div class="login-center-input">
					<input type="text" id="username" placeholder="请输入您的用户名"  onblur="this.placeholder='请输入您的用户名'"/>
					<div class="login-center-input-text">用户名</div>
				</div>
			</div>
			<div class="login-center clearfix">
				<div class="login-center-img"><img src="img/password.png"/></div>
				<div class="login-center-input">
					<input type="password" id="password" placeholder="请输入您的密码"  onblur="this.placeholder='请输入您的密码'"/>
					<div class="login-center-input-text">密码</div>
				</div>
			</div>
			<div class="login-center clearfix">
				<div class="login-center-img"><img src="img/yzm.png"/></div>
				<div class="login-center-input">
					<input type="text" id="yan"  placeholder="请输入验证码"  onblur="this.placeholder='请输入您的密码'"/ style="width: 50%;">
					<span id="wo"><img style="width: 48%;" src="" id="imgs"></span>
					<div class="login-center-input-text">验证码</div>
		
				</div>
			</div>
			<div class="login-button" id="btn">
				添加
			</div>
		</div>
		<div class="sk-rotating-plane"></div>
</div>

<!-- scripts -->
<script src="js/particles.min.js"></script>
<script src="js/app.js"></script>
<script>
	var key=null
	$(function(){
		captchaFun()
		$('#btn').click(btnFun)
		$('#imgs').click(captchaFun)
	})
	function btnFun(){
           user= $('#username').val()
           pwd=$('#password').val()
            let data={
        username:$('#username').val(),
        password:$('#password').val(),
        captcha:$('#yan').val(),
        key:key,
       }
       $.ajax({
        url:'https://api.zzgoodqc.cn/api/user',
        type:'post',
        data:data,
        success:function(res){
            console.log(res);
            if(res.code==200){
				alert('添加成功')
				$('#username').val('')
             $('#password').val('')
             $('#yan').val('')
                captchaFun()
                }else{
					alert(res.message)
					captchaFun()
				}
        },
        dataType:'json'
       })
        
	}
	//获取验证码
function captchaFun(){
        $.ajax({
            url:'https://api.zzgoodqc.cn/api/captcha',
            type:'get',
            success:function(res){
                if(res.code==200){
                    key=res.data.key
                    $('#imgs').prop('src',res.data.img)
                }
            },
            dataType:'json'
        })
    }
</script>


</body>
</html>